package com.xywh.wanandroid.compose_ui.splash

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.MutableTransitionState
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.xywh.composeLibrary.view.XxImage
import com.xywh.wanandroid.R

@Composable
fun SplashScreen(
    navigateHome: () -> Unit
) {
    val transitionState = remember {
        MutableTransitionState(false).apply {
            targetState = true
            navigateHome.invoke()
        }
    }
    AnimatedVisibility(
        visibleState = transitionState,
        enter = fadeIn(
            initialAlpha = 0.3f,
            animationSpec = tween(3000)
        ),
//            exit = fadeOut(animationSpec = tween(5000)),
    ) {
        Column(
            Modifier
                .background(MaterialTheme.colorScheme.primary)
                .fillMaxSize(),
            verticalArrangement = Arrangement.Center,
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {

            Box(
                modifier = Modifier
                    .border(width = 2.dp, color = Color.White, shape = CircleShape)
                    .size(110.dp),
                contentAlignment = Alignment.Center,
            ) {
                XxImage(id = R.mipmap.logo, size = 110.dp)
            }


        }
    }
}
